/**************************************************************

This file determines the number of nurse programs from the CHED data;
*Run after "0 Clean Raw CHED Data.do"
*********************************************************/
capture log close
capture program drop _all
capture macro drop _all
drop _all
set more off

*UPDATE PATH;
global ched_data 
global ched_data_clean 
global psced_data 

*********************************************************

clear
use "${ched_data}finalched_v2.dta", clear 

gen year=substr(acadyear,1,4)
destring year, replace
drop acadyear

drop if province==""															

drop if pscedgroup=="."															
drop if pscedgroup==""															

replace pscedgroup="89" if pscedgroup=="46" | pscedgroup=="90" | pscedgroup=="47"	//This reclassifies some pscedgroups so that they are consistent across year
replace pscedgroup="0" if pscedgroup=="00"											

merge m:1 pscedgroup using "${psced_data}pscedmatch.dta", replace update		//labels the pscedgroups
drop if _m==2
drop _m

*This identifies which programs are nursing programs. 
gen nurse=1 if six_digitprogdis=="501200" & pscedgroup=="50"
replace nurse=1 if six_digitprogdis=="34" & pscedgroup=="50"
replace nurse=1 if six_digitprogdis=="500202" & pscedgroup=="50"
replace nurse=1 if six_digitprogdis=="503001" & pscedgroup=="50"
replace nurse=1 if six_digitprogdis=="509903" & pscedgroup=="50"
replace nurse=0 if nurse==.

replace pscedgroup="100" if nurse==1
replace disciplinegroup="Nursing" if nurse==1

drop if typedata=="Graduations" | typedata=="Graduations (not by gender)"		//need to drop otherwise double counting schools

sum emftotal if nurse==1&year<2000, detail

gen nonnurse=1 if nurse!=1
replace nonnurse=0 if nurse==1

*Assigns value of 1 to institutions that have a nursing or non-nursing program.
collapse (max)nurse nonnurse, by(province year instcode insttype)

*Create indicator for institution has both nursing and non-nursing programs;
gen both=1 if nurse==1&nonnurse==1

gen both2=both
forvalues x=1990/2013 {
	gen temp1=0
	replace temp1 = 1 if nurse==0 & nonnurse==1 & year<`x'
	egen temp2 = max(temp1), by(instcode)
	replace both2 = 0 if temp2==0 & year==`x'
	drop temp1 temp2
}

gen temp1=.
forvalues x=1990/2013 {
	replace temp1=`x' if nurse==1&temp1==.&year==`x'
}

egen temp2=min(temp1), by(instcode)
gen newnurse=1 if year==temp2
replace newnurse=0 if both2==1
replace newnurse=0 if year==1994

rename both2 oldnn_newnurse

*Create indicator for institution has only a nursing program
gen nurse_only=1 if nonnurse!=1

*Collapse to province level
collapse (sum)nurse nonnurse both nurse_only oldnn_newnurse newnurse, by(province year insttype)
rename nurse nurseprog_
rename nonnurse nonnurseprog_
rename both bothprog_
rename nurse_only nurseonlyprog_
rename oldnn_newnurse oldnn_newnurse_
rename newnurse newnurse_

*Filling in observations for provinces without nurse enrollment 
reshape wide nurseprog nonnurseprog bothprog nurseonlyprog oldnn_newnurse newnurse, i(province year) j(insttype) string
reshape wide nurseprog_* nonnurseprog_* bothprog_* nurseonlyprog_* oldnn_newnurse_* newnurse_*,  i(province) j(year)
order province nurseprog_private* nurseprog_public* nonnurseprog_private* nonnurseprog_public* bothprog_private* bothprog_public* nurseonlyprog_private* nurseonlyprog_public* oldnn_newnurse_private* oldnn_newnurse_public* newnurse_private* newnurse_public*
forvalues i=1990(1)2013 {
	replace nurseprog_private`i'=0 if nurseprog_private`i'==.
	replace nurseprog_public`i'=0 if nurseprog_public`i'==.
	replace nonnurseprog_private`i'=0 if nonnurseprog_private`i'==.
	replace nonnurseprog_public`i'=0 if nonnurseprog_public`i'==.
	replace bothprog_private`i'=0 if bothprog_private`i'==.
	replace bothprog_public`i'=0 if bothprog_public`i'==.
	replace nurseonlyprog_private`i'=0 if nurseonlyprog_private`i'==.
	replace nurseonlyprog_public`i'=0 if nurseonlyprog_public`i'==.
	replace oldnn_newnurse_private`i'=0 if  oldnn_newnurse_private`i'==.
	replace oldnn_newnurse_public`i'=0 if oldnn_newnurse_public`i'==.
	replace newnurse_private`i'=0 if newnurse_private`i'==.
	replace newnurse_public`i'=0 if newnurse_public`i'==.
	}
reshape long nurseprog_private nurseprog_public nonnurseprog_private nonnurseprog_public bothprog_private bothprog_public nurseonlyprog_private nurseonlyprog_public oldnn_newnurse_private oldnn_newnurse_public newnurse_private newnurse_public, i(province) j(year)

gen nurseprog=nurseprog_private+nurseprog_public
gen nonnurseprog=nonnurseprog_private+nonnurseprog_public
gen bothprog=bothprog_private+bothprog_public
gen nurseonlyprog=nurseonlyprog_private+nurseonlyprog_public
gen oldnn_newnurse=oldnn_newnurse_private+oldnn_newnurse_public
gen newnurse=newnurse_private+newnurse_public

tostring year, gen(temp)
gen matcher=province+temp
drop temp

*Reassign to original provinces before provincial divisons;
replace province="ZAMBOANGA DEL SUR" if province=="ZAMBOANGA SIBUGAY"											
replace province="SURIGAO DEL NORTE" if province=="DINAGAT ISLANDS"

replace province="SOUTH COTABATO" if province=="SARANGANI"						
replace province="DAVAO DEL NORTE" if province=="COMPOSTELA VALLEY"

replace province="KALINGA" if province=="APAYAO"						


replace province="THIRD DISTRICT" if province=="FIRST DISTRICT"					
replace province="THIRD DISTRICT" if province=="SECOND DISTRICT"				
replace province="THIRD DISTRICT" if province=="FOURTH DISTRICT"
drop matcher

*collapsing because of merging of province data for Metro Manila and other reassigned provinces
collapse (sum) nurseprog* nonnurseprog* bothprog* nurseonlyprog* oldnn_newnurse* newnurse*, by(province year)

drop if year<=1990 | year==2014

*Replacing missing values/extreme outliers with average before and after
*Results are also robust to simply dropping these
replace nurseprog=2 if province=="AKLAN" & year==2004
replace nurseprog_private=nurseprog_private+2 if province=="AKLAN" & year==2004

replace nurseprog=2 if province=="BASILAN" & year==2001
replace nurseprog_private=nurseprog_private+1 if province=="BASILAN" & year==2001
replace nurseprog_public=nurseprog_public+1 if province=="BASILAN" & year==2001

replace nurseprog=2 if province=="BOHOL" & year==1997
replace nurseprog_private=nurseprog_private+2 if province=="BOHOL" & year==1997

replace nurseprog=9 if province=="CAMARINES SUR" & year==2004
replace nurseprog_private=nurseprog_private+3 if province=="CAMARINES SUR" & year==2004

replace nurseprog=4 if province=="CAPIZ" & year==2004
replace nurseprog_private=nurseprog_private+2 if province=="CAPIZ" & year==2004

replace nurseprog=8 if province=="CEBU" & year==1997
replace nurseprog_private=nurseprog_private+5 if province=="CEBU" & year==1997
replace nurseprog_public=nurseprog_public+1 if province=="CEBU" & year==1997

replace nurseprog=8 if province=="CEBU" & year==1996
replace nurseprog_private=nurseprog_private+2 if province=="CEBU" & year==1996

replace nurseprog=8 if province=="DAVAO DEL SUR" & year==1996
replace nurseprog_private=nurseprog_private+2 if province=="DAVAO DEL SUR" & year==1996

replace nurseprog=4 if province=="ILOCOS NORTE" & year==1997
replace nurseprog_private=nurseprog_private+1 if province=="ILOCOS NORTE" & year==1997

replace nurseprog=6 if province=="ILOILO" & year==2004
replace nurseprog_private=nurseprog_private+4 if province=="ILOILO" & year==2004

replace nurseprog=7 if province=="NEGROS OCCIDENTAL" & year==2004
replace nurseprog_private=nurseprog_private+6 if province=="NEGROS OCCIDENTAL" & year==2004

replace nurseprog=2 if province=="NEGROS ORIENTAL" & year==1996
replace nurseprog_private=nurseprog_private+1 if province=="NEGROS ORIENTAL" & year==1996

replace nurseprog=2 if province=="NEGROS ORIENTAL" & year==1997
replace nurseprog_private=nurseprog_private+2 if province=="NEGROS ORIENTAL" & year==1997

replace nurseprog=4 if province=="QUEZON" & year==1996
replace nurseprog_private=nurseprog_private+2 if province=="QUEZON" & year==1996

replace nurseprog=1 if province=="RIZAL" & year==1996
replace nurseprog_private=nurseprog_private+1 if province=="RIZAL" & year==1996

replace nurseprog=4 if province=="SOUTH COTABATO" & year==2006
replace nurseprog_private=nurseprog_private+2 if province=="SOUTH COTABATO" & year==2006

*Non-nurse programs
replace nonnurseprog=18 if province=="AGUSAN DEL NORTE" & year==1996
replace nonnurseprog_private=nonnurseprog_private+9 if province=="AGUSAN DEL NORTE" & year==1996

replace nonnurseprog=8 if province=="ANTIQUE" & year==1996
replace nonnurseprog_private=nonnurseprog_private+1 if province=="ANTIQUE" & year==1996
replace nonnurseprog_public=nonnurseprog_public+1 if province=="ANTIQUE" & year==1996

replace nonnurseprog=3 if province=="BASILAN" & year==1995
replace nonnurseprog_private=nonnurseprog_private+1 if province=="BASILAN" & year==1995
replace nonnurseprog_public=nonnurseprog_public+1 if province=="BASILAN" & year==1995

replace nonnurseprog=3 if province=="BASILAN" & year==1996
replace nonnurseprog_private=nonnurseprog_private+1 if province=="BASILAN" & year==1996

replace nonnurseprog=18 if province=="BATAAN" & year==2007
replace nonnurseprog_private=nonnurseprog_private+2 if province=="BATAAN" & year==2007

replace nonnurseprog=13 if province=="BOHOL" & year==1997
replace nonnurseprog_private=nonnurseprog_private+10 if province=="BOHOL" & year==1997
replace nonnurseprog_public=nonnurseprog_public+2 if province=="BOHOL" & year==1997

replace nonnurseprog=43 if province=="BULACAN" & year==2007
replace nonnurseprog_private=nonnurseprog_private+2 if province=="BULACAN" & year==2007
replace nonnurseprog_public=nonnurseprog_public+1 if province=="BULACAN" & year==2007

replace nonnurseprog=7 if province=="CAPIZ" & year==1996
replace nonnurseprog_public=nonnurseprog_public+1 if province=="CAPIZ" & year==1996

replace nonnurseprog=40 if province=="CEBU" & year==1997
replace nonnurseprog_private=nonnurseprog_private+23 if province=="CEBU" & year==1997
replace nonnurseprog_public=nonnurseprog_public+10 if province=="CEBU" & year==1997

replace nonnurseprog=15 if province=="DAVAO DEL NORTE" & year==1996
replace nonnurseprog_private=nonnurseprog_private+4 if province=="DAVAO DEL NORTE" & year==1996

replace nonnurseprog=14 if province=="LA UNION" & year==1996
replace nonnurseprog_public=nonnurseprog_public+2 if province=="LA UNION" & year==1996

replace nonnurseprog=14 if province=="LA UNION" & year==1997
replace nonnurseprog_public=nonnurseprog_public+2 if province=="LA UNION" & year==1997

replace nonnurseprog=4 if province=="MARINDUQUE" & year==1996
replace nonnurseprog_private=nonnurseprog_private+1 if province=="MARINDUQUE" & year==1996

replace nonnurseprog=11 if province=="NEGROS ORIENTAL" & year==1997
replace nonnurseprog_private=nonnurseprog_private+6 if province=="NEGROS ORIENTAL" & year==1997
replace nonnurseprog_public=nonnurseprog_public+4 if province=="NEGROS ORIENTAL" & year==1997

replace nonnurseprog=3 if province=="SIQUIJOR" & year==1997
replace nonnurseprog_private=nonnurseprog_private+2 if province=="SIQUIJOR" & year==1997
replace nonnurseprog_public=nonnurseprog_public+1 if province=="SIQUIJOR" & year==1997

replace nonnurseprog=14 if province=="SOUTH COTABATO" & year==1995
replace nonnurseprog_private=nonnurseprog_private+3 if province=="SOUTH COTABATO" & year==1995
replace nonnurseprog_public=nonnurseprog_public+1 if province=="SOUTH COTABATO" & year==1995

replace nonnurseprog=4 if province=="SULU" & year==1996
replace nonnurseprog_public=nonnurseprog_public+3 if province=="SULU" & year==1996

replace nonnurseprog=11 if province=="SURIGAO DEL SUR" & year==1996
replace nonnurseprog_private=nonnurseprog_private+2 if province=="SURIGAO DEL SUR" & year==1996
replace nonnurseprog_public=nonnurseprog_public+2 if province=="SURIGAO DEL SUR" & year==1996

replace nonnurseprog=11 if province=="ZAMBALES" & year==1996
replace nonnurseprog_private=nonnurseprog_private+2 if province=="ZAMBALES" & year==1996

replace nonnurseprog=10 if province=="ZAMBOANGA DEL NORTE" & year==1995
replace nonnurseprog_private=nonnurseprog_private+4 if province=="ZAMBOANGA DEL NORTE" & year==1995

replace nonnurseprog=11 if province=="ZAMBOANGA DEL NORTE" & year==1996
replace nonnurseprog_private=nonnurseprog_private+2 if province=="ZAMBOANGA DEL NORTE" & year==1996

replace nonnurseprog=17 if province=="ZAMBOANGA DEL SUR" & year==1995
replace nonnurseprog_private=nonnurseprog_private+4 if province=="ZAMBOANGA DEL SUR" & year==1995

replace nonnurseprog=17 if province=="ZAMBOANGA DEL SUR" & year==1996
replace nonnurseprog_private=nonnurseprog_private+5 if province=="ZAMBOANGA DEL SUR" & year==1996
replace nonnurseprog_public=nonnurseprog_public+1 if province=="ZAMBOANGA DEL SUR" & year==1996

save "${ched_data}nurse_prog.dta", replace


